import state from './state'
import * as type from './type.js'

// 导入mint-ui插件
import { MessageBox } from 'mint-ui'

const mutations = {
  // 文章收藏
  [type.SET_ARTICLE] (state, data) {
    state.article.push(data)
    localStorage.setItem('article', JSON.stringify(state.article))
  },
  // 文章取消收藏（文章删除）
  del: (state, index) => {
    MessageBox.confirm('确定取消收藏该文章么？').then(action => {
      state.article.splice(index, 1)
      localStorage.setItem('article', JSON.stringify(state.article))
    })
  },
  // 设置地址
  [type.SET_ADDRESS] (state, data) {
    // 添加数据
    state.address.push(data)
    // 保存到本地数据
    localStorage.setItem('address', JSON.stringify(state.address))
  },
  // 删除地址
  rubbish: (state, index) => {
    MessageBox.confirm('确定删除收货地址嘛？').then(action => {
      state.address.splice(index, 1)
      localStorage.setItem('address', JSON.stringify(state.address))
    })
  }

}

export default mutations
